﻿using PubSubGeneric.WCFContracts;
using PubSubGeneric.WCFContracts.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

namespace PubSubGeneric.WCFPublishingClient
{
    public class WCFPublishingService : IPublishingService
    {
        IWCFPublishingServiceAdapter PublishingService;
        public ISubscriptionCatalog SubscriptionCatalog
        {
            get;
            set;
        }

        public WCFPublishingService()
        {
            ChannelFactory<IWCFPublishingServiceAdapter> chn = new ChannelFactory<IWCFPublishingServiceAdapter>("PubSubGeneric.IPublishingService");
            PublishingService = chn.CreateChannel();
        }

        public void Publish<T>(string topicName, T args)
        {
            string objstr = WCFSerializer.Serialize(args, typeof(T));
            PublishingService.Publish(topicName, objstr, Util.GetFullTypeName<T>());
        }

    }
}
